package ldh.common.testui.handle.impl;

import javafx.scene.Parent;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import ldh.common.testui.constant.TreeNodeType;
import ldh.common.testui.handle.BaseTreeNodeService;
import ldh.common.testui.model.TreeNode;
import ldh.common.testui.util.RegionUtil;

import java.util.ArrayList;
import java.util.List;

public class ParamTreeNodeService extends BaseTreeNodeService {

    public ParamTreeNodeService(TreeView<TreeNode> treeView, TabPane tabPane, ContextMenu contextMenu, TreeNodeType treeNodeType) {
        super(treeView, tabPane, contextMenu, treeNodeType);
    }

    @Override
    protected void mouseClicked(TreeItem<TreeNode> treeItem) {
        if (treeItem == null || treeItem.getValue() == null) return;
        if (treeItem.getValue().getTreeNodeType() != treeNodeType) return;
        Tab tab = getExistedTab(treeItem.getValue());
        if (tab == null) {
            tab = new Tab("属性管理");
            tab.setUserData(treeItem.getValue());
            tabPane.getTabs().add(tab);
            tabPane.getSelectionModel().select(tab);
            Parent parent = RegionUtil.paramPane(treeItem);
            tab.setContent(parent);
        } else {
            tabPane.getSelectionModel().select(tab);
        }
    }

    @Override
    public List<MenuItem> buildNodeMenuItem(TreeItem<TreeNode> treeItem) {
        return new ArrayList<>();
    }
}
